﻿<%@ Page Title="Журнал производства работ" Language="C#" MasterPageFile="~/MasterPages/Site.Master" AutoEventWireup="true" CodeBehind="Journal.aspx.cs" Inherits="Arm2015.WebUI.App_Modules.Journal" %>

<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.2, Version=11.2.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridLookup" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Web.v11.2, Version=11.2.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxLoadingPanel" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.2, Version=11.2.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%--<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>--%>
<asp:Content ID="Content2" ContentPlaceHolderID="siteContent" runat="server">

    <dx:ASPxLoadingPanel ID="journalLoadingPanel" runat="server" ClientInstanceName="journalLoadingPanel" />

    <table style="width: 100%;">
        <tr>
            <td style="width: 50%;"></td>
            <td style="width: 50%">
                <asp:ObjectDataSource ID="dsContracts" runat="server" TypeName="Arm2015.WebUI.App_Modules.Journal" SelectMethod="GetContracts" />
                <asp:UpdatePanel ID="contractsUpdatePanel" runat="server">
                    <ContentTemplate>
                        <dx:ASPxComboBox ID="cbContracts" runat="server" DataSourceID="dsContracts" ValueField="C_CONTRACT" ValueType="System.Int32" Width="100%" AutoPostBack="true" OnSelectedIndexChanged="cbContracts_SelectedIndexChanged">
                            <ClientSideEvents ValueChanged="function(s,e){journalLoadingPanel.Show();}" Init="function(s,e){journalLoadingPanel.Hide();}" />
                            <Columns>
                                <dx:ListBoxColumn FieldName="FIRST_SELECT" Visible="false" />
                                <dx:ListBoxColumn FieldName="C_CONTRACTOR" Visible="false" />
                                <dx:ListBoxColumn Caption="Наименование блока" FieldName="N_BLOCK" />
                                <dx:ListBoxColumn Caption="Подрядчик" FieldName="N_CONTRACTOR" />
                                <dx:ListBoxColumn Caption="Номер генконтракта" FieldName="N_GENERAL_CONTRACT" />
                            </Columns>
                        </dx:ASPxComboBox>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
    </table>
    
    <asp:ObjectDataSource ID="dsMakers" runat="server" TypeName="Arm2015.WebUI.App_Modules.Journal" SelectMethod="GetContractorMakers" />

    <asp:ObjectDataSource ID="dsObjects" runat="server" TypeName="Arm2015.WebUI.App_Modules.Journal" SelectMethod="GetContractObjects" />

    <asp:ObjectDataSource ID="dsElements" runat="server" TypeName="Arm2015.WebUI.App_Modules.Journal" SelectMethod="GetElements" />

    <asp:ObjectDataSource ID="dsObjectElements" runat="server" TypeName="Arm2015.WebUI.App_Modules.Journal" SelectMethod="GetObjectElements">
        <SelectParameters>
            <asp:Parameter Name="objectId" DbType="Int32" />
            <asp:Parameter Name="elementId" DbType="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>

    <asp:ObjectDataSource ID="dsObjectElementWorks" runat="server" TypeName="Arm2015.WebUI.App_Modules.Journal" SelectMethod="GetObjectElementWorks">
        <SelectParameters>
            <asp:Parameter Name="contractId" DbType="Int32" />
            <asp:Parameter Name="monthId" DbType="Int32" />
            <asp:Parameter Name="objectElementId" DbType="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>

    <asp:UpdatePanel ID="journalUpdatePanel" runat="server">
        <ContentTemplate>
            <dx:ASPxGridView ID="gridJournal" runat="server" KeyFieldName="C_JOURNAL"   OnStartRowEditing="gridJournal_StartRowEditing" OnCellEditorInitialize="gridJournal_CellEditorInitialize" OnBeforeGetCallbackResult="gridJournal_BeforeGetCallbackResult">
                <Settings ShowFilterRow="true" ShowFilterRowMenu="true" />
                <SettingsPager Position="TopAndBottom" />
                <SettingsEditing EditFormColumnCount="1" Mode="PopupEditForm" PopupEditFormHorizontalAlign="WindowCenter" PopupEditFormVerticalAlign="WindowCenter" PopupEditFormWidth="900" />
                <Columns>
                    <dx:GridViewBandColumn Caption="Управление">
                        <Columns>
                            <dx:GridViewCommandColumn ButtonType="Image">
                                <EditButton Visible="true" Image-Url="../Content/Images/Grid/edit.gif" />
                            </dx:GridViewCommandColumn>
                        </Columns>
                    </dx:GridViewBandColumn>
                    <dx:GridViewDataDateColumn Caption="Дата производства работ" FieldName="DATE" SortOrder="Descending" 
                        EditFormSettings-VisibleIndex="0" />
                    <dx:GridViewDataTextColumn Caption="ФИО производителя работ" FieldName="N_MAKER" EditFormSettings-VisibleIndex="1">
                        <EditItemTemplate>
                            <asp:UpdatePanel ID="lcMakersUpdatePanel" runat="server">
                                <ContentTemplate>
                                    <dx:ASPxGridLookup ID="lcMakers" runat="server" DataSourceID="dsMakers" KeyFieldName="C_MAKER" Width="100%" TextFormatString="{0}">
                                        <ClientSideEvents Init="setFullGridViewLookupPopupWidth"/>
                                        <GridViewProperties>
                                            <Settings ShowFilterRow="true" ShowFilterRowMenu="true" />
                                            <SettingsPager PageSize="5" />
                                        </GridViewProperties>
                                        <Columns>
                                            <dx:GridViewDataTextColumn Caption="Производитель работ" FieldName="N_MAKER" />
                                        </Columns>
                                    </dx:ASPxGridLookup>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </EditItemTemplate>
                    </dx:GridViewDataTextColumn>

                    <dx:GridViewDataColumn FieldName="C_OBJECT" Visible="false" />
                    <dx:GridViewDataTextColumn Caption="Код и наименование объекта содержания" FieldName="N_OBJECT" EditFormSettings-VisibleIndex="2">
                        <EditItemTemplate>
                            <asp:UpdatePanel ID="lcObjectsUpdatePanel" runat="server">
                                <ContentTemplate>
                                    <dx:ASPxGridLookup ID="lcObjects" runat="server" KeyFieldName="C_OBJECT" Width="100%" TextFormatString="{1}" DataSourceID="dsObjects" >
                                        <ClientSideEvents Init="setFullGridViewLookupPopupWidth"/>
                                        <GridViewProperties>
                                            <Settings ShowFilterRow="true" ShowFilterRowMenu="true" />
                                            <SettingsPager PageSize="5" />
                                        </GridViewProperties>
                                        <Columns>
                                            <dx:GridViewDataTextColumn Caption="Код" FieldName="CODE" />
                                            <dx:GridViewDataTextColumn Caption="Наименование" FieldName="N_OBJECT" />
                                        </Columns>
                                    </dx:ASPxGridLookup>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </EditItemTemplate>
                    </dx:GridViewDataTextColumn>

                    <dx:GridViewDataColumn FieldName="C_TYPE_ELEMENT" Visible="false" />
                    <dx:GridViewDataColumn FieldName="C_ELEMENT" Visible="false" />
                    <dx:GridViewDataTextColumn Caption="Наименование элемента" FieldName="N_ELEMENT" EditFormSettings-VisibleIndex="3">
                        <EditItemTemplate>
                            <asp:UpdatePanel ID="lcElementsUpdatePanel" runat="server">
                                <ContentTemplate>
                                    <dx:ASPxGridLookup ID="lcElements" runat="server" DataSourceID="dsElements" KeyFieldName="C_ELEMENT" Width="100%" TextFormatString="{0}" >
                                        <ClientSideEvents Init="setFullGridViewLookupPopupWidth"/>
                                        <GridViewProperties>
                                            <Settings ShowFilterRow="true" ShowFilterRowMenu="true" />
                                            <SettingsPager PageSize="5" />
                                        </GridViewProperties>
                                        <Columns>
                                            <dx:GridViewDataTextColumn Caption="Наименование элемента" FieldName="N_ELEMENT" />
                                            <dx:GridViewDataTextColumn Caption="Тип элемента" FieldName="N_TYPE_ELEMENT" />
                                        </Columns>
                                    </dx:ASPxGridLookup>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </EditItemTemplate>
                    </dx:GridViewDataTextColumn>

                    <dx:GridViewBandColumn Caption="Местоположение участка выполнения работ">
                        <Columns>
                            <dx:GridViewDataTextColumn Caption="Расположение" FieldName="LOCATION" EditFormSettings-VisibleIndex="4">
                                <EditItemTemplate>
                                    <asp:UpdatePanel ID="lcObjectElementsUpdatePanel" runat="server">
                                        <ContentTemplate>
                                            <dx:ASPxGridLookup ID="lcObjectElements" runat="server" DataSourceID="dsObjectElements" KeyFieldName="C_OBJECT_ELEMENT" Width="100%" TextFormatString="{0} - {1} - {2}">
                                                <ClientSideEvents Init="setFullGridViewLookupPopupWidth" />
                                                <GridViewProperties>
                                                    <Settings ShowFilterRow="true" ShowFilterRowMenu="true" />
                                                    <SettingsPager PageSize="5" />
                                                </GridViewProperties>
                                                <Columns>
                                                    <dx:GridViewDataTextColumn Caption="Расположение" FieldName="LOCATION" />
                                                    <dx:GridViewDataSpinEditColumn Caption="Начало, км" FieldName="BEGKM" PropertiesSpinEdit-DisplayFormatString="{0:f3}">
                                                        <PropertiesSpinEdit DecimalPlaces="3" />
                                                    </dx:GridViewDataSpinEditColumn>
                                                    <dx:GridViewDataSpinEditColumn Caption="Конец, км" FieldName="ENDKM" PropertiesSpinEdit-DisplayFormatString="{0:f3}">
                                                        <PropertiesSpinEdit DecimalPlaces="3" />
                                                    </dx:GridViewDataSpinEditColumn>
                                                </Columns>
                                            </dx:ASPxGridLookup>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </EditItemTemplate>
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataSpinEditColumn Caption="Начало, км" FieldName="BEGKM" EditFormSettings-Visible="False">
                                <PropertiesSpinEdit DecimalPlaces="3" DisplayFormatString="{0:f3}" />
                            </dx:GridViewDataSpinEditColumn>
                            <dx:GridViewDataSpinEditColumn Caption="Конец, км" FieldName="ENDKM" EditFormSettings-Visible="False">
                                <PropertiesSpinEdit DecimalPlaces="3" DisplayFormatString="{0:f3}" />
                            </dx:GridViewDataSpinEditColumn>
                        </Columns>
                    </dx:GridViewBandColumn>

                    <dx:GridViewDataTextColumn Caption="Наименование работы" FieldName="N_WORK">
                        <EditFormSettings VisibleIndex="5" />
                        <EditItemTemplate>
                            <asp:UpdatePanel ID="lcObjectElementWorksUpdatePanel" runat="server">
                                <ContentTemplate>
                                    <dx:ASPxGridLookup ID="lcObjectElementWorks" runat="server" DataSourceID="dsObjectElementWorks" KeyFieldName="C_WORK" Width="100%" TextFormatString="{0}" >
                                        <ClientSideEvents Init ="setFullGridViewLookupPopupWidth"/>
                                        <GridViewProperties>
                                            <Settings ShowFilterRow="true" ShowFilterRowMenu="true" />
                                            <SettingsPager PageSize="5" />
                                        </GridViewProperties>
                                        <Columns>
                                            <dx:GridViewDataTextColumn Caption="Наименование работы" FieldName="N_WORK" />
                                            <dx:GridViewDataComboBoxColumn FieldName="PRIORITET" />
                                        </Columns>
                                    </dx:ASPxGridLookup>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </EditItemTemplate>
                    </dx:GridViewDataTextColumn>
                    <dx:GridViewDataSpinEditColumn Caption="Объем работ" FieldName="WORK_VALUE" />

                    <dx:GridViewDataSpinEditColumn FieldName="DECIMAL_PLACES" Visible="false" />
                    <dx:GridViewDataTextColumn Caption="Единица измерения" FieldName="N_UNIT" EditFormSettings-Visible="False" />

                    <dx:GridViewDataSpinEditColumn Caption="Стоимость единицы" FieldName="COSTONEWORK_NOW">
                        <PropertiesSpinEdit DecimalPlaces="2" DisplayFormatString="{0:c}" />
                        <EditFormSettings Visible="False" />
                    </dx:GridViewDataSpinEditColumn>
                    <dx:GridViewDataSpinEditColumn Caption="Стоимость работ" FieldName="WORK_COST">
                        <EditFormSettings Visible="False" />
                        <PropertiesSpinEdit DecimalPlaces="2" DisplayFormatString="{0:c}" />
                    </dx:GridViewDataSpinEditColumn>
                </Columns>
            </dx:ASPxGridView>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="siteScripts" runat="server">
    <script type="text/javascript">
        function setFullGridViewLookupPopupWidth(s,e)
        {
            s.GetGridView().SetWidth(s.GetWidth());
        }
    </script>
</asp:Content>

